package com.jiashihui.schema_lgorithm.schema.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jiashihui
 * @describe: 猎头
 * @date 2019/03/14
 */
public class HeadHunterImpl implements Subject {

    /* 求职者列表 */
    private List<Observer> userList;

    /* 工作列表 */
    private List<String> jobList;

    public HeadHunterImpl() {
        userList = new ArrayList<Observer>();
        jobList = new ArrayList<String>();
    }

    @Override
    public void addObserver(Observer observer) {
        userList.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        userList.remove(observer);
    }

    @Override
    public void notifyAllObservers() {
        if (null != userList && userList.size() > 0) {
            for (Observer observer : userList) {
                observer.update(this);
            }
        }
    }

    /**
     * 增加工作
     *
     * @author jiashihui
     * @param job 工作名称
     */
    public void addJob(String job) {
        this.jobList.add(job);
        notifyAllObservers();
    }

    public List<String> getJobList() {
        return jobList;
    }

    @Override
    public String toString() {
        return jobList.toString();
    }
}
